package com.aring.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.aring.bean.BattleInfo;
import com.aring.bean.MatchInfo;
import com.aring.bean.Page;
import com.aring.bean.Place;
import com.aring.bean.PlaceNumber;
import com.aring.bean.ReserveInfo;
import com.aring.bean.School;
import com.aring.bean.TimeTable;
import com.aring.bean.User;
import com.aring.dao.BattleInfoDao;
import com.aring.dao.MatchInfoDao;
import com.aring.dao.PlaceDao;
import com.aring.dao.PlaceNumberDao;
import com.aring.dao.ReserveInfoDao;
import com.aring.dao.SchoolDao;
import com.aring.dao.TimeTableDao;
import com.aring.dao.UserDao;
import com.aring.service.UserService;

@Service("userService")
public class UserServiceImpl implements UserService{

	@Autowired
	private UserDao userDao;
	
	@Autowired
	private SchoolDao schoolDao;
	
	@Autowired
	private PlaceDao placeDao;
	
	@Autowired
	private BattleInfoDao battleInfoDao;
	
	@Autowired
	private PlaceNumberDao placeNumberDao;
	
	@Autowired
	private TimeTableDao timeTableDao;
	
	@Autowired
	private ReserveInfoDao reserveInfoDao;
	
	@Autowired
	private MatchInfoDao matchInfoDao;
	
	
	
	public int register(User user) {
		return userDao.insertUser(user);
	}

	
	
	public User login(User user) {
	    User user2 =  userDao.selectByAccAndPass(user);	  
	    if(user2 == null) throw new RuntimeException("账号或密码错误");
		return user2;
	}


	
	public int settingInfo(User user) {
		return userDao.updateByIdOrAccount(user);
	}


	
	public User getUserInfo(User user) {
		 return userDao.selectById(user);
	}

	
	public List<School> getSchoolInfo() {
		return schoolDao.selectAll();
	}


	
	public List<Place> getPlaces(int schoolId) {		
		return placeDao.selectBySchoolId(schoolId);
	}

	
	public int publicGame(BattleInfo battleInfo) {
		return battleInfoDao.insert(battleInfo);
	}


	
	public List<BattleInfo> getBattleInfoByPage(Page page) {
		return battleInfoDao.selectByPage(page);
	}


	
	public List<PlaceNumber> getPlaceNumbers(int placeId) {
		return placeNumberDao.selectPlaceNumberByPlaceId(placeId);
	}


	
	public List<TimeTable> getTables(int placeNumberId) {
		return timeTableDao.selectByplaceNumberId(placeNumberId);
	}

	
	public int reservePalce(ReserveInfo info) {
		return reserveInfoDao.insert(info);
	}


	
	public int updateTimeTableStatus(TimeTable table) {
		return timeTableDao.updateStatus(table);
	}


	
	public List<MatchInfo> getMatchInfosByPage(Page page) {
		return matchInfoDao.selectByPage(page);
	}


	
}
